package git.soulbgm.yarn.wordcount;

import git.soulbgm.mapreduce.utils.DriverUtil;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.util.Tool;

/**
 * @author SoulBGM
 * @version 1.0
 * @date 2021/12/5 22:11
 */
public class WordCountTool implements Tool {

    private Configuration conf;

    @Override
    public int run(String[] args) throws Exception {
        Job job = DriverUtil.createJob(WordCountDriver.class, WordCountMapper.class, WordCountReducer.class,
                Text.class, IntWritable.class, Text.class, IntWritable.class,
                new Path(args[0]), new Path(args[1]));
        // 7 提交job
        boolean result = job.waitForCompletion(true);
        return result ? 0 : 1;
    }

    @Override
    public void setConf(Configuration conf) {
        this.conf = conf;
    }

    @Override
    public Configuration getConf() {
        return conf;
    }
}
